{% extends 'base.html' %}
{% block content %}
<h2>{{ goods.title }}</h2>
<div class="row">
    <div class="col-md-6">
        <img src="{{ goods.image_url }}" class="img-fluid rounded" alt="{{ goods.title }}">
    </div>
    <div class="col-md-6">
        <p><strong>描述：</strong>{{ goods.description }}</p>
        <p><strong>价格：</strong>￥{{ goods.price }}</p>
        <p><strong>成色：</strong>{{ goods.condition }}</p>
        <p><strong>发布时间：</strong>{{ goods.create_time.strftime('%Y-%m-%d') }}</p>

        {#添加卖家信息#}
        <div>
          <h4>卖家信息：</h4>
          <p>电话：{{ goods.seller.phone }}</p>
          <p>邮箱：{{ goods.seller.email }}</p>
        </div>

        {# 查看商品销售状态 #}
        {% if goods.is_sold %}
          <span class="btn btn-danger">已售</span>
        {% else %}
          <span class="btn btn-warning">在售</span>
        {% endif %}

        {#收藏和取消收藏#}
        {% if goods in current_user.favorites %}
            <a href="{{ url_for('goods.unfavorite', goods_id=goods.id) }}" class="btn btn-danger">取消收藏</a>
        {% else %}
            <a href="{{ url_for('goods.favorite', goods_id=goods.id) }}" class="btn btn-primary">收藏</a>
        {% endif %}
    </div>
</div>

<hr>
<h4>留言区</h4>
{% if current_user.is_authenticated %}
<form method="post" action="/goods/leave_message/{{ goods.id }}">
    <div class="mb-3">
        <textarea class="form-control" name="content" rows="3" placeholder="留下你的留言..."></textarea>
    </div>
    <button class="btn btn-primary" type="submit">提交留言</button>
</form>
{% else %}
<p>请 <a href="/login">登录</a> 后留言</p>
{% endif %}

<hr>
{% for msg in messages.items %}
<div class="card mb-2">
    <div class="card-body">
        <p class="card-text">{{ msg.content }}</p>
        <footer class="blockquote-footer">{{ msg.user.username }} 于 {{ msg.created_at.strftime('%Y-%m-%d %H:%M') }}</footer>
    </div>
</div>
{% endfor %}

<nav>
  <ul class="pagination">
    {% if messages.has_prev %}
      <li class="page-item"><a class="page-link" href="?page={{ messages.prev_num }}">上一页</a></li>
    {% endif %}
    <li class="page-item active"><span class="page-link">{{ messages.page }}/{{ messages.pages }}</span></li>
    {% if messages.has_next %}
      <li class="page-item"><a class="page-link" href="?page={{ messages.next_num }}">下一页</a></li>
    {% endif %}
  </ul>
</nav>
{% endblock %}